import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.util.List;

public class JedisDemoString {
    public static void test1(Jedis jedis) {
        //mget mset
        //getrange setrange
        //incr decr
        //append
        System.out.println("mget 和 mset的使用");
        jedis.flushAll();
        jedis.mset("key1", "value1", "key2", "value2");
        List<String> list = jedis.mget("key1", "key2", "key3");
        System.out.println(list);
    }
    public static void test2(Jedis jedis) {
        System.out.println("getrange 和setrange的使用");
        jedis.flushAll();
        jedis.set("key1", "ajdakjdskajdkaj");
        System.out.println(jedis.getrange("key1", 2, 6));
        //输出的是新改变字符串的长度
        System.out.println(jedis.setrange("key1", 2, "555555"));
        System.out.println(jedis.get("key1"));
    }
    public static void test3(Jedis jedis) {
        jedis.flushAll();
        jedis.set("key1", "1000");
        jedis.incr("key1");
        System.out.println(jedis.get("key1"));
        System.out.println(jedis.decr("key1"));
    }
    public static void test4(Jedis jedis) {
        jedis.flushAll();
        jedis.set("key1", "abcd");
        System.out.println(jedis.append("key1", "cnfafjha"));
        System.out.println(jedis.get("key1"));
    }
    public static void main(String[] args) {
        JedisPool jedisPool = new JedisPool("tcp://localhost:8888");
        try(Jedis jedis = jedisPool.getResource()) {
            jedis.auth("maihao1122");
            //测试类
            //test1(jedis);
            //test2(jedis);
            //test3(jedis);
            test4(jedis);
        }
    }
}
